//
//  RootTabBarController.m
//  RedManStock
//
//  Created by lanou3g on 15/7/19.
//  Copyright (c) 2015年 lanou3g. All rights reserved.
//

#import "RootTabBarController.h"
#import "BaseScrollViewController.h"
#import "BaseTableViewController.h"
#import "HomeViewController.h"
#import "CommentViewController.h"
#import "HotPostViewController.h"
#import "CommunityViewController.h"
#import "InformationViewController.h"
#import "QuotationCollectionViewController.h"
#import "NewsViewController.h"
#import "StockSearchResultTVC.h"
#import "DataHandle.h"
#import "MyAccountViewController.h"
#import "TradeOperateViewController.h"
#import "EntrustViewController.h"
@interface RootTabBarController ()

@end

@implementation RootTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor=[UIColor whiteColor];
    
//    [UILabel appearance].backgroundColor=[UIColor clearColor];
    //初始化数据
    [self setupNecessaryData];
    //加载controller
    [self setupViewControllers];
}

#pragma mark - 初始化数据 -
- (void)setupNecessaryData{
    //通过bundle中的stockInfo初始化沙盒中的stockCollect.plist文件，之后搜索和自选股都用后者
    [[DataHandle shareHandle] initStockInfoPlist];
    
    //创建user.plist文件
    [[DataHandle shareHandle] initUserInfoPlist];
}

#pragma mark - 控制器 -
- (void)setupViewControllers{
    
//首页
    
    HomeViewController *homeVC=[[HomeViewController alloc]initWithHeader:YES footer:YES];
    UINavigationController *nv1=[[UINavigationController alloc]initWithRootViewController:homeVC];
    nv1.tabBarItem.image=[UIImage imageNamed:@"homePage@2x"];
//    BaseTableViewController *testVC1=[[BaseTableViewController alloc]initWithHeader:YES footer:YES];
//    testVC1.tableView.rowHeight=50;
//    
//    BaseTableViewController *testVC2=[[BaseTableViewController alloc]init];
//    testVC2.tableView.rowHeight=100;
    
//社区
    HotPostViewController *hotPostVC=[[HotPostViewController alloc]initWithHeader:YES footer:YES];
    CommunityViewController *communityVC=[[CommunityViewController alloc]initWithHeader:YES footer:NO];
    BaseScrollViewController *baseSVC2=[[BaseScrollViewController alloc]initWithTitles:@[@"热门动态",@"社区导航"] controllers:@[hotPostVC,communityVC]];
    UINavigationController *nv2=[[UINavigationController alloc]initWithRootViewController:baseSVC2];
    nv2.tabBarItem.image=[UIImage imageNamed:@"community@2x"];
    
//买卖
    MyAccountViewController *myAccountVC=[[MyAccountViewController alloc]initWithHeader:YES footer:NO];
    TradeOperateViewController *tradeOperateVC=[[TradeOperateViewController alloc]init];
    //传参数，因为滑动到的时候是买入页面
    tradeOperateVC.buyOrSell=YES;
    EntrustViewController *entrustVC=[[EntrustViewController alloc]initWithHeader:NO footer:NO];
    BaseScrollViewController *baseSVC3=[[BaseScrollViewController alloc]initWithTitles:@[@"我的账户",@"买入",@"委托查询"] controllers:@[myAccountVC,tradeOperateVC,entrustVC]];
    UINavigationController *nv3=[[UINavigationController alloc]initWithRootViewController:baseSVC3];
    nv3.tabBarItem.image=[UIImage imageNamed:@"trade@2x"];
    
//市场
    //这里必须初始化layout
    UICollectionViewFlowLayout *layout=[[UICollectionViewFlowLayout alloc]init];
    
    QuotationCollectionViewController *quotaionVC=[[QuotationCollectionViewController alloc]initWithCollectionViewLayout:layout];
    
    InformationViewController *informationVC=[[InformationViewController alloc]initWithHeader:YES footer:YES];
//    NewsViewController *newsVC=[[NewsViewController alloc]initWithHeader:YES footer:YES];
    
    BaseScrollViewController *baseSCV4=[[BaseScrollViewController alloc]initWithTitles:@[@"行情",@"资讯"] controllers:@[quotaionVC, informationVC]];
    UINavigationController *nv4=[[UINavigationController alloc]initWithRootViewController:baseSCV4];
    nv4.tabBarItem.image=[UIImage imageNamed:@"market@2x"];
    
    nv1.tabBarItem.title=@"首页";
    nv2.tabBarItem.title=@"社区";
    nv3.tabBarItem.title=@"买卖";
    nv4.tabBarItem.title=@"市场";
    
    
    self.tabBar.tintColor=[UIColor redColor];
    
#warning 到时候改为4个
    self.viewControllers=@[nv1,nv2,nv3,nv4];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
